<?php

require_once dirname(__FILE__) . '/../lib/ct_documento_comentarioGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/ct_documento_comentarioGeneratorHelper.class.php';

/**
 * ct_documento_comentario actions.
 *
 * @package    ingenyo-biblio
 * @subpackage ct_documento_comentario
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class ct_documento_comentarioActions extends autoCt_documento_comentarioActions
{

  public function executeNew(sfWebRequest $request)
  {
    $documento = CtDocumentoPeer::retrieveByPK($this->getUser()->getAttribute('id_documento'));
    $this->form = new CtDocumentoComentarioForm(null, array('id_documento', $documento->getId()));
    $this->CtDocumentoComentario = $this->form->getObject();
    $this->CtDocumento = $documento;

     return $this->renderPartial('new', array(
       'form' => $this->form,
       'CtDocumentoComentario' => $this->CtDocumentoComentario,
       'CtDocumento' => $this->CtDocumento,
       'configuration' => $this->configuration,
       'helper' => $this->helper
     ));
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->form = $this->configuration->getForm();
    $this->CtDocumentoComentario = $this->form->getObject();

    $CtDocumentoComentario = $this->processForm($request, $this->form);

    return $this->renderPartial('comentario', array('CtDocumentoComentario' => $CtDocumentoComentario));
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';

      $CtDocumentoComentario = $form->save();

      $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $CtDocumentoComentario)));


      $this->getUser()->setFlash('notice', $notice);
    }
    else
    {
      $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
    }
    
    return $CtDocumentoComentario;

  }

}
